define(["echarts"], function (echarts) {
  return {
    creatEchar: function (obj, opt) {

      //定义echarts样式
      $("#" + obj.id).css({
        "width": obj.chartWih,
        "height": obj.chartHig,
        "margin": obj.margin,
        "background": obj.background
      });

      var  dom = document.getElementById(obj.id);
      var  myCharts = echarts.init(dom);

      var app = {
        count: 11
      }

      switch (true) {
        case opt.series[0].type == "bar":
          setInterval(function () {
            var axisData = (new Date()).toLocaleTimeString().replace(/^\D*/, '');

            var data0 = opt.series[0].data;
            var data1 = opt.series[1].data;
            data0.shift();
            data0.push(Math.round(Math.random() * 1000));
            data1.shift();
            data1.push((Math.random() * 10 + 5).toFixed(1) - 0);

            opt.xAxis[0].data.shift();
            opt.xAxis[0].data.push(axisData);
            opt.xAxis[1].data.shift();
            opt.xAxis[1].data.push(app.count++);

            //使用制定的配置项和数据显示图表
            myCharts.setOption(opt);

          }, 2100);
          break;
        default:
          myCharts.setOption(opt);
          break;
      }
    }
  }
});
